package models.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import models.repo.IRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CommonDAO {
	@Autowired
	private IRepository repo;

	public Date getSysDate() throws Exception {
		return (Date) repo.getObjectByQuery("SELECT SYSDATE FROM DUAL", null);
	}
	
	public Date getFirstDateOfMonth() throws Exception {
		return (Date) repo.getObjectByQuery("SELECT TRUNC(SYSDATE, 'MONTH') FROM DUAL", null);
	}
	public Date getLastDate(Date date) throws Exception{		
		List<Object> params = new ArrayList<Object>();
		params.add(date);
		return (Date) repo.getObjectByQuery(" select last_day(?) from dual ", params);
	}
}
